package com.ruoyi.yl.careSetting.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.yl.careSetting.vo.YlCareCategoryVo;
import com.ruoyi.yl.careSetting.service.IYlCareCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 护理类别Controller
 *
 * @author Ming
 * @date 2025-10-21
 */
@Api(tags = "护理类别Controller")
@RestController
@RequestMapping("/pg/careCategory")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class YlCareCategoryController extends BaseController {

    private final IYlCareCategoryService ylCareCategoryService;

    @ApiOperation("查询护理类别列表")
    @GetMapping("/list")
    public TableDataInfo<YlCareCategoryVo> list(YlCareCategoryVo entity) {
        return ylCareCategoryService.queryList(entity);
    }

    @ApiOperation("查询护理类别所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(YlCareCategoryVo entity) {
        return AjaxResult.success("查询成功", ylCareCategoryService.queryAll(entity));
    }

    @ApiOperation("导出护理类别列表")
    @Log(title = "护理类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YlCareCategoryVo entity) {
        List<YlCareCategoryVo> list = ylCareCategoryService.queryAll(entity);
        ExcelUtil<YlCareCategoryVo> util = new ExcelUtil<>(YlCareCategoryVo.class);
        util.exportExcel(response, list, "护理类别数据");
    }

    @ApiOperation("获取护理类别详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", ylCareCategoryService.queryById(id));
    }

    @ApiOperation("新增护理类别")
    @Log(title = "护理类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YlCareCategoryVo entity) {
        return toAjax(ylCareCategoryService.save(entity));
    }

    @ApiOperation("修改护理类别")
    @Log(title = "护理类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YlCareCategoryVo entity) {
        return toAjax(ylCareCategoryService.updateById(entity));
    }

    @ApiOperation("删除护理类别")
    @Log(title = "护理类别", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ylCareCategoryService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
